<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        .select {
            width: 200px;
            margin: 50px;
        }
        .select p {
            border: 1px solid #000;
            line-height: 30px;
            padding-left: 20px;
        }
        .select ul {
            line-height: 30px;
            border: 1px solid #000;
            display: none;
        }
        .select ul li {
            border-bottom: 1px solid #000;
            padding-left: 20px;
        }
        .select ul li:last-child{
            border-bottom: 0;
        }
    </style>
</head>
<body>

    <!-- <select name="" id="">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select> -->


    <div class="select">
        <p>请选择</p>
        <ul>
            <li>湖北省</li>
            <li>河北省</li>
            <li>湖男省</li>
            <li>河南省</li>
            <li>江西省</li>
        </ul>
    </div>


    <script>

        var oP = document.querySelector('p') ;
        var oUl = document.querySelector('ul') ;
        var oLis = oUl.querySelectorAll('li') ;
        console.log(oLis);


        oP.addEventListener('click' , function(e) {
            // p 的事件触发了document的事件   导致ul一开始是显示的，然后又被隐藏了   需要阻止事件冒泡
            e.stopPropagation() ;
            // 显示ul
            oUl.style.display = 'block' ;


            // 给li绑定点击事件
            for(var i = 0 ; i < oLis.length ; i++) {
                oLis[i].addEventListener('click' , function() {
                    console.log(1);
                    oP.innerHTML = this.innerHTML ;
                    oUl.style.display = 'none' ;
                })
            }

            document.addEventListener('click' , function() {
                oUl.style.display = 'none' ;
            })

        })

    </script>
    
</body>
</html>